package com.medical.goods.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.medical.goods.entity.SeckillSessionEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.medical.goods.entity.GoodsSeckillRelationEntity;
import com.medical.goods.service.GoodsSeckillRelationService;
import com.medical.common.utils.PageUtils;
import com.medical.common.utils.R;



/**
 * 
 *
 * @author wen
 * @email 1023076426@qq.com
 * @date 2021-08-27 15:37:41
 */
@RestController
@RequestMapping("goods/goodsseckillrelation")
public class GoodsSeckillRelationController {
    @Autowired
    private GoodsSeckillRelationService goodsSeckillRelationService;

    /**
     * 获取二天内所有需要秒杀的商品
     * @return
     */

    @GetMapping("/session2dayGoods")
    public R getSession2daysGoodsId(){
        List<SeckillSessionEntity> sessionEntities=goodsSeckillRelationService.getSession2daysGoodsId();
        return R.ok().setData(sessionEntities);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = goodsSeckillRelationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		GoodsSeckillRelationEntity goodsSeckillRelation = goodsSeckillRelationService.getById(id);

        return R.ok().put("goodsSeckillRelation", goodsSeckillRelation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody GoodsSeckillRelationEntity goodsSeckillRelation){
		goodsSeckillRelationService.save(goodsSeckillRelation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody GoodsSeckillRelationEntity goodsSeckillRelation){
		goodsSeckillRelationService.updateById(goodsSeckillRelation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		goodsSeckillRelationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
